"""initial migration (not)

Revision ID: 1fcab2512ee2
Revises: 
Create Date: 2024-05-28 21:28:03.138865

"""

from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op
from dataline.models.base import CustomUUIDType

# revision identifiers, used by Alembic.
revision: str = "1fcab2512ee2"
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "connections",
        sa.Column("dsn", sa.String(), nullable=False),
        sa.Column("database", sa.String(), nullable=False),
        sa.Column("name", sa.String(), nullable=True),
        sa.Column("dialect", sa.String(), nullable=True),
        sa.Column("is_sample", sa.Boolean(), server_default="false", nullable=False),
        sa.Column("id", CustomUUIDType(), nullable=False),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_connections")),
        sa.UniqueConstraint("dsn", name=op.f("uq_connections_dsn")),
    )
    op.create_table(
        "media",
        sa.Column("key", sa.String(), nullable=False),
        sa.Column("blob", sa.LargeBinary(), nullable=False),
        sa.Column("id", CustomUUIDType(), nullable=False),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_media")),
    )
    op.create_table(
        "user",
        sa.Column("name", sa.String(length=100), nullable=True),
        sa.Column("openai_api_key", sa.String(), nullable=True),
        sa.Column("preferred_openai_model", sa.String(), nullable=True),
        sa.Column("langsmith_api_key", sa.String(), nullable=True),
        sa.Column("sentry_enabled", sa.Boolean(), server_default=sa.text("1"), nullable=False),
        sa.Column("id", CustomUUIDType(), nullable=False),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_user")),
    )
    op.create_table(
        "conversations",
        sa.Column("connection_id", CustomUUIDType(), nullable=False),
        sa.Column("name", sa.String(), nullable=False),
        sa.Column("created_at", sa.String(), nullable=False),
        sa.Column("id", CustomUUIDType(), nullable=False),
        sa.ForeignKeyConstraint(
            ["connection_id"],
            ["connections.id"],
            name=op.f("fk_conversations_connection_id_connections"),
            ondelete="CASCADE",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_conversations")),
    )
    op.create_table(
        "messages",
        sa.Column("content", sa.Text(), nullable=False),
        sa.Column("role", sa.String(), nullable=False),
        sa.Column("created_at", sa.String(), nullable=True),
        sa.Column("conversation_id", CustomUUIDType(), nullable=False),
        sa.Column("options", sa.JSON(), nullable=True),
        sa.Column("id", CustomUUIDType(), nullable=False),
        sa.ForeignKeyConstraint(
            ["conversation_id"],
            ["conversations.id"],
            name=op.f("fk_messages_conversation_id_conversations"),
            ondelete="CASCADE",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_messages")),
    )
    op.create_table(
        "results",
        sa.Column("content", sa.Text(), nullable=False),
        sa.Column("type", sa.String(), nullable=False),
        sa.Column("created_at", sa.String(), nullable=True),
        sa.Column("message_id", CustomUUIDType(), nullable=False),
        sa.Column("linked_id", CustomUUIDType(), nullable=True),
        sa.Column("id", CustomUUIDType(), nullable=False),
        sa.ForeignKeyConstraint(
            ["message_id"], ["messages.id"], name=op.f("fk_results_message_id_messages"), ondelete="CASCADE"
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_results")),
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table("results")
    op.drop_table("messages")
    op.drop_table("conversations")
    op.drop_table("user")
    op.drop_table("media")
    op.drop_table("connections")
    # ### end Alembic commands ###
